// pages/main/guajiewangpu/guajiewangpu.js
import http from '../../../class/Utils/Http'
import user from '../../../class/Utils/User'
import tips from '../../../class/Utils/Tips'
Page({
    data: {
        inputdisabled: false,//input禁用状态
        s: 1,
        user: wx.getStorageSync("user")
    },
    onLoad: function (options) {
        var that = this
        that.getinfo(that)
    },
    getinfo: function (that) {
        var data = {
            uid: wx.getStorageSync("user").userid
        }
        http.req("/Mingpian/gua_wangpu", data, function (res) {
            console.log(res)
            if (res.cid > 0) {
                that.setData({
                    info: res,
                    s: 0,
                    inputValue:res.c_login
                })
            } else {
                that.setData({
                    s: 1
                })
            }
        })
    },
    //获取input内容
    bindKeyInput: function (e) {
        var that = this
        that.setData({
            inputValue: e.detail.value
        })

    },
    //清空input
    emptyinput: function () {
        var that = this
        that.setData({
            inputValue: '',
        })
        console.log(that.data.autofocus)
    },
    //提交申请
    tijiaoshenqing: function () {
        var that = this
        var data = {
            uid: that.data.user.userid,
            com_login: that.data.inputValue
        }
        console.log(data)
        http.req("/Mingpian/guajie", data, function (res) {
            if (res.code == '215') {
                tips.ok(res.msg_val)
                that.getinfo(that)
            } else {
                that.setData({
                    msg_val:res.msg_val
                })
            }
        })
    },
    //撤回申请
    chehuishenqing: function () {
        var that = this
        tips.modal("是否确认要测回",true,'function',false,function () {
            var data ={
                uid: that.data.user.userid,
                com_login: that.data.info.c_login
            }
            http.req("/Mingpian/del_wangpu", data, function (res) {
                if (res.code == '216') {
                    tips.ok(res.msg_val)
                    that.getinfo(that)
                    that.setData({
                        inputValue:''
                    })
                } else {
                    that.setData({
                        msg_val:res.msg_val
                    })
                }
            })
        })

    },
    //查看旺铺
    chakanwangpu: function () {
        var that = this
        var info = this.data.info
        if(info.wx_user.toocle_cid == 0){
            tips.error("暂无旺铺")
            return false
        }
        if(info.wx_user.toocle_cid==100387){
            tips.redirectTo('/pages/mingpian/wangpu/index/index?mid='+info.mid);
        }else{
            tips.redirectTo("/pages/toocle/shop/index/index?cid="+info.wx_user.toocle_cid+"&time="+info.wx_user.toocle_ctime+"&quanmenuid=1");
        }
    },
})